import { prop, Ref, modelOptions, arrayProp } from "@typegoose/typegoose";
import { Commodity } from "./commodity.model";
import { User } from "./user.model";
import { ApiModelProperty } from "@nestjs/swagger";

@modelOptions({
  schemaOptions: {
    timestamps: true
  }
})

export class Order {
  @ApiModelProperty({ description: '商品id', example: ['ObjectId'], type: [String] })
  @arrayProp({ itemsRef: 'Commodity' })
  commoditis: Ref<Commodity>[]

  @ApiModelProperty({ description: '用户id', example: 'ObjectId', type: [String] })
  @prop({ ref: User })
  user: Ref<User>

  @prop({
    get(val) {
      return val;
    },
    set(val) {
      return this._id.toString();
    },
    default() {
      return this._id.toString()
    }
  })
  orderNum?: Readonly<string>
}